package avicit.bdp.dds.api.controller;

import avicit.bdp.dds.api.dto.NoteBookDTO;
import avicit.bdp.dds.api.service.NoteBookService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * NoteBook服务Rest接口定义
 */
@RestController
@RequestMapping("/api/bdp/dds/phm/notebook")
@Api(tags = "NoteBook服务Rest接口定义")
public class NoteBookController {
    @Autowired
    private NoteBookService noteBookService;

    /**
     * 新增NoteBook服务
     */
    @ApiOperation(value = "新增NoteBook服务")
    @PostMapping("/insert")
    public ResponseMsg<Boolean> insert(@RequestBody NoteBookDTO noteBookDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.noteBookService.createNoteBook(noteBookDTO));

        return responseMsg;
    }

    /**
     * 修改NoteBook服务
     */
    @ApiOperation(value = "修改NoteBook服务")
    @PostMapping("/update")
    public ResponseMsg<Boolean> update(@RequestBody NoteBookDTO noteBookDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.noteBookService.updateNoteBook(noteBookDTO));

        return responseMsg;
    }

    /**
     * 删除Notebook服务
     */
    @ApiOperation(value = "删除Notebook服务")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String")
    @DeleteMapping("/delete")
    public ResponseMsg<Boolean> delete(@RequestParam("id") String id) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(this.noteBookService.deleteNoteBook(id));
        return responseMsg;
    }

    /**
     * 分页查询Notebook服务
     */
    @ApiOperation(value = "分页查询Notebook服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String"),
            @ApiImplicitParam(name = "projectId", value = "项目空间id", dataType = "String"),
            @ApiImplicitParam(name = "remark", value = "描述", dataType = "String"),
            @ApiImplicitParam(name = "showed", value = "是否显示", dataType = "Int"),
            @ApiImplicitParam(name = "pageNo", value = "当前页", dataType = "Int"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "Int")
    })
    @GetMapping("/searchByPage")
    public ResponseMsg<QueryRespBean<NoteBookDTO>> searchByPage(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String projectId,
            @RequestParam(required = false) String remark,
            @RequestParam(required = false) Integer showed,
            @RequestParam(required = false) Integer pageNo,
            @RequestParam (required = false)Integer pageSize) {
        ResponseMsg<QueryRespBean<NoteBookDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.noteBookService.searchNoteBookByPage(name, projectId, remark, showed, pageNo,
                pageSize));

        return responseMsg;
    }

    /**
     * 列举NoteBook服务列表
     */
    @ApiOperation(value = "列举NoteBook服务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String"),
            @ApiImplicitParam(name = "remark", value = "描述", dataType = "String"),
            @ApiImplicitParam(name = "showed", value = "是否显示", dataType = "Int")
    })
    @GetMapping("/listNoteBook")
    public ResponseMsg<List<NoteBookDTO>> listNoteBook(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String remark,
            @RequestParam(required = false) Integer showed) {
        ResponseMsg<List<NoteBookDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(this.noteBookService.listNoteBook(name, remark, showed));
        return responseMsg;
    }

    /**
     * 查询NoteBook服务详情
     */
    @ApiOperation(value = "查询NoteBook服务详情")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String")
    @GetMapping("/getDetails")
    public ResponseMsg<NoteBookDTO> getDetails(
            @RequestParam(required = false) String id) {
        ResponseMsg<NoteBookDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(this.noteBookService.getNoteBookDetails(id));
        return responseMsg;
    }

    /**
     * 启动/停止NoteBook服务
     */
    @ApiOperation(value = "启动/停止NoteBook服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "String"),
            @ApiImplicitParam(name = "commandType", value = "状态", dataType = "Int")
    })
    @PostMapping("/execute")
    public ResponseMsg<Boolean> execute(
            @RequestParam String id,
            @RequestParam Integer commandType) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.noteBookService.execute(id, commandType));

        return responseMsg;
    }

    /**
     * 获取NoteBook启动日志
     */
    @ApiOperation(value = "获取NoteBook启动日志")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String")
    @GetMapping("/queryLog")
    public ResponseMsg<String> queryLog(@RequestParam String id) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(this.noteBookService.queryLog(id));
        return responseMsg;
    }
}
